package net.dntuan.training.mvc.dao.impl;

import net.dntuan.training.mvc.dao.UserDao;
import net.dntuan.training.mvc.domain.User;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

@Repository("userDao")
public class UserDaoImpl extends BaseDaoImpl<User> implements UserDao {

    public UserDaoImpl() {
        setClazz(User.class);
    }

    @Override
    public User getUserByUsername(String username) {
        Criteria criteria = this.getCurrentSession().createCriteria(this.clazz);
        criteria.add(Restrictions.eq("username", username));
        return (User) criteria.uniqueResult();
    }

}
